#define _CRT_SECURE_NO_WARNINGS 1
//https://leetcode.cn/problems/balanced-binary-tree/description/
typedef struct TreeNode TreeNode;

int get_height(TreeNode* node) {
    if (node == NULL) {
        return 0;
    }
    return 1 + fmax(get_height(node->left), get_height(node->right));
}


bool isBalanced(TreeNode* node) {
    if (node == NULL) {
        return 1;
    }
    int left_height = get_height(node->left);
    int right_height = get_height(node->right);
    if (abs(left_height - right_height) > 1) {
        return 0;
    }
    return isBalanced(node->left) && isBalanced(node->right);
}